import { defHttp } from '/@/common/util/axios';

enum Api {
  taskDetail = '/emp/hubTeamResultOrder/getWorkDetail', //按任务登记项目
  taskContentDetail = '/epm/team/RationReg/getRationTypeDetailByCode', //按任务登记项目详情
  create = '/epm/team/RationReg/create',
  audit = '/epm/team/RationReg/executeTeamassess', //工分登记审核
  auditnew = '/epm/team/RationReg/updateAndTeamassess',
  pepContentDetail = '/epm/team/RationReg/getRationTypeDetail', //按人员登记详情
  editTask = '/emp/hubTeamResultOrder/getWorkCheckInDetail', //工分登记数据详情
  update = '/epm/team/RationReg/update', //工分登记修改
  submit = '/epm/team/RationReg/executeSubmit', //工分登记提交
  refuse = '/epm/team/RationReg/executeReject', //工分登记驳回
  showModeSelect = '/epm/team/RationReg/isShowRationType',

  list = '/emp/hubTeamResultOrder/getPage', //工分登记-分页
  getWorkTree = '/emp/hubTeamResultOrder/getWorkList', //工作类型列表
  getBaseRelTree = '/emp/common/getBaseRelTree', //用户列表
  header = '/emp/dynamicTable/getTeamResultOrderXsHeader', //动态表头
  twoHeader = '/emp/dynamicTable/getResultOrderForTwoDimensionalHeader', //考核登记-工单二维表评分表头
  save = '/emp/hubTeamResultOrder/save', // 工分登记-保存-按事-按人
  haveTwoData = '/emp/hubTeamResultOrder/getWorkCheckInDetailForTwoDimensional', // 获取工分登记详情-二维表
  importExcel = '/emp/hubTeamResultOrder/importExcel',
  exportXls = '/emp/hubTeamResultOrder/exportXls',
  delete = '/emp/hubTeamResultOrder/delete', //删除
}

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.delete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const deleteBatch = (id) => defHttp.post({ url: `${Api.delete}?ids=${id}` });
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
export const haveTwoData = (params) => defHttp.post({ url: Api.haveTwoData, params });
export const list = (params) => defHttp.get({ url: Api.list, params });
export const save = (params) => defHttp.post({ url: Api.save, params });
export const getUserTreeApi = "";
export const getWorkTreeApi = "";

export const getBaseRelTreeList = (params?) => defHttp.get({ url: Api.getBaseRelTree, params });
export const getWorkTreeList = (params?) => defHttp.post({ url: Api.getWorkTree, params });


/**
 *
 * @param params 动态表头
 * @returns
 */
export const getColumn = (params) => defHttp.post({ url: Api.header, params });
// 二维表动态表头
export const getTwoColumn = (params) => defHttp.post({ url: Api.twoHeader, params });

/**
 * author:lhw
 * description: 获取任务登记项目详情
 * @params: @params 查询参数
 * date: 2023/2/13
 * lastModify: 2023/2/13
 */
export const getTaskDetail = (params) => defHttp.get({ url: Api.taskDetail, params }, { joinParamsToUrl: true });

/**
 * author:lhw
 * description:获取按任务登记项目详情
 * @params: @
 * date: 2023/2/23
 * lastModify: 2023/2/23
 */
export const getTaskContentDetail = (params) => defHttp.post({ url: Api.taskContentDetail, params }, { joinParamsToUrl: true });

/**
 * author:lhw
 * description:获取按人员登记项目详情
 * @params: @
 * date: 2023/2/23
 * lastModify: 2023/2/23
 */
export const getPepContentDetail = (params) => defHttp.post({ url: Api.pepContentDetail, params }, { joinParamsToUrl: true });

/**
 * author:lhw
 * description: 递归格式化树 禁用不可点击数据项
 * @params: @
 * date: 2023/2/21
 * lastModify: 2023/2/21
 */
function formatRes(list) {
  list.forEach((l) => {
    if (!l.isRation) {
      l.disabled = true;
    }
    if (l.children) {
      formatRes(l.children);
    }
  });
}

/**
 * author:lhw
 * description: 新增工分登记
 * @params: @
 * date: 2023/2/23
 * lastModify: 2023/2/23
 */
export const createPoints = (params) => defHttp.post({ url: Api.create, params });

/**
 * author:lhw
 * description: 工分登记审核
 * @params: @
 * date: 2023/2/23
 * lastModify: 2023/2/23
 */
export const auditPoints = (params) => defHttp.post({ url: Api.audit, params }, { joinParamsToUrl: true });
//只需要审核不需要掉保存接口
export const auditPointsNew = (params) => defHttp.post({ url: Api.auditnew, params }, { joinParamsToUrl: true });

/**
 * author:lhw
 * description: 修改按任务登记工分
 * @params: @
 * date: 2023/2/24
 * lastModify: 2023/2/24
 */
export const editTask = (params) => defHttp.get({ url: Api.editTask, params });

export const updateData = (params) => defHttp.post({ url: Api.update, params });

/**
 * author:lhw
 * description:工分登记提交
 * @params: @
 * date: 2023/3/3
 * lastModify: 2023/3/3
 */
export const submitPoints = (params) => defHttp.post({ url: Api.submit, params }, { joinParamsToUrl: true });

/**
 * author:lhw
 * description:工分登记驳回
 * @params: @
 * date: 2023/3/4
 * lastModify: 2023/3/4
 */
export const refusePoints = (params) => defHttp.post({ url: Api.refuse, params }, { joinParamsToUrl: true });

/**
 * author:lhw
 * description: 工分等级下拉框系数查询
 * @params: @list 为响应式proxy对象
 * date: 2023/3/4
 * lastModify: 2023/3/4
 */
export function getOptions(fieldName, list, rationCode) {
  const params = {
    fieldName: fieldName,
    rationCode: rationCode,
  };
  return new Promise((resolve) => {
    defHttp.get({ url: '/epm/ration/teamRationtypevalue/getRationTypeValue', params }).then((res) => {
      res.map((v) => {
        v.label = v.quotietyName;
        v.value = v.quotiety.toString();
      });
      list.value[fieldName] = res;
      resolve(res);
    });
  });
}

/**
 * author:lhw
 * description: 工分等级下拉框系数查询 按用户登记
 * @params: @list 为响应式proxy对象
 * date: 2023/3/4
 * lastModify: 2023/3/4
 */
export function getUserOptions(fieldName, list, rationCode) {
  const params = {
    fieldName: fieldName,
    rationCode: rationCode,
  };
  return new Promise((resolve) => {
    defHttp.get({ url: '/epm/ration/teamRationtypevalue/getRationTypeValue', params }).then((res) => {
      res.map((v) => {
        v.label = v.quotietyName;
        v.value = v.quotiety;
      });
      list.value[rationCode] = {};
      list.value[rationCode][fieldName] = res;
      resolve(res);
    });
  });
}

/**
 * author:lhw
 * description: 查询是否显示分摊模式选择下拉框
 * @params: @
 * date: 2023/3/8
 * lastModify: 2023/3/8
 */
export const showModeSelect = () => defHttp.post({ url: Api.showModeSelect });
